package com.lionel.websocket.jna;

import com.lionel.websocket.webSockek.OneWebSocket;
import org.junit.Test;

import javax.websocket.Session;
import java.io.UnsupportedEncodingException;

public class JnaStart {
    //启动程序
    public static void start(Session session,int flag) throws UnsupportedEncodingException {
        byte sid[] = new byte[37];
        byte name[] = new byte[31];
        byte sex[] = new byte[3];
        byte folk[] = new byte[10];
        byte birth[] = new byte[9];
        byte code[] = new byte[19];
        byte add[] = new byte[71];
        byte agency[] = new byte[31];
        byte expirestart[] = new byte[9];
        byte expireend[] = new byte[9];
        int ret=0;

        if (CLibrary.sdtapi.InitComm(1001)==1)
        {
            System.out.println("connect OK! 请按Ctrl+C 退出程序");
            ret=CLibrary.sdtapi.GetSAMIDToStr(sid);
            if (flag != 1)
            {
                System.out.println("GetSAMIDToStr="+ret);
                return;
            }
            System.out.println(new String(sid));

            while (true)
            {
                ret=CLibrary.sdtapi.Authenticate();
                if (ret==1)
                {
                    System.out.println("======================================");

                    ret=CLibrary.sdtapi.ReadBaseInfos(name,sex,folk,birth,code,add,agency,expirestart,expireend);
                    if (ret!=1)
                    {
                        System.out.println("ReadBaseInfosPhoto="+ret);
                        return;
                    }
                    //CLibrary.sdtapi.HID_BeepLED(true,true,50);
                    //CLibrary.sdtapi.HID_BeepLED(false,false,50);
                    //CLibrary.sdtapi.HID_BeepLED(true,true,50);
                    //处理乱码
                    System.out.println(new String(name,"GBK"));
                    System.out.println(new String(sex ,"GBK"));
                    System.out.println(new String(folk ,"GBK"));
                    System.out.println(new String(birth ,"GBK"));
                    System.out.println(new String(code ,"GBK"));
                    System.out.println(new String(add ,"GBK"));
                    System.out.println(new String(agency ,"GBK"));
                    System.out.println(new String(expirestart ,"GBK"));
                    System.out.println(new String(expireend ,"GBK"));
                    //发送消息给socket
                    OneWebSocket.sendMessage(new String(name,"GBK"),session);
                }
            }

        }
        else
        {
            System.out.println("connect error from java!");

        }
    }
}
